<?php
/**
 * Created by PhpStorm.
 * User: 86188
 * Date: 2021/3/5
 * Time: 9:23
 */

namespace app\service;

//微信模板信息
class wxtplService
{

    //审核成功结果通知
    public function json_tempalte_checksuccess($openid,$url,$first,$keyword1,$keyword2,$keyword3,$remark){
        //模板消息
        $post_data = array(
            "touser"=>$openid, //推送给谁,openid
            "template_id"=>"CX_VgW1nBFb0Izx8MZT60qK6RwCdkZw_AZMN4A9-ztA", //微信后台的模板信息id
            "url"=>$url, //下面为预约看房模板示例
            "data"=> array(
                "first" => array(
                    "value"=>$first,
                    "color"=>"#173177"
                ),
                "keyword1" => array(
                    "value"=>$keyword1,//审核类型
                    "color"=>"#173177"
                ),
                "keyword2" => array(
                    "value"=>$keyword2,//审核结果
                    "color"=>"#173177"
                ),
                "keyword3" => array(
                    "value"=>$keyword3,//审核意见
                    "color"=>"#173177"
                ),

                "remark"=>array(
                    "value"=>$remark,
                    "color"=>"#173177"
                ),
            )
        );
        //将上面的数组数据转为json格式
        $template = json_encode($post_data);
        return $template;
    }
    //认证退回通知
    public function json_tempalte_back($openid,$url,$first,$keyword1,$keyword2,$remark){
        //模板消息
        $post_data = array(
            "touser"=>$openid, //推送给谁,openid
            "template_id"=>"XG2v-X2zXW_B7-I4beqRXXiw17fJQDXRXJjyQVmtssg", //微信后台的模板信息id
            "url"=>$url, //下面为预约看房模板示例
            "data"=> array(
                "first" => array(
                    "value"=>$first,
                    "color"=>"#173177"
                ),
                "keyword1" => array(
                    "value"=>$keyword1,//审核退回
                    "color"=>"#173177"
                ),
                "keyword2" => array(
                    "value"=>$keyword2,////认证房屋信息
                    "color"=>"#173177"
                ),

                "remark"=>array(
                    "value"=>$remark,//"通知时间:".date("Y-m-d H:i:s"), //传的变量
                    "color"=>"#173177"
                ),
            )
        );
        //将上面的数组数据转为json格式
        $template = json_encode($post_data);
        return $template;
    }
    /**
     * 将审核模板消息json格式化
     */
    public function json_tempalte_review($openid,$tenpalate_id,$url,$first,$keyword1,$keyword2,$keyword3,$keyword4,$remark){
        //模板消息
        $post_data = array(
            "touser"=>$openid, //推送给谁,openid
            "template_id"=>$tenpalate_id, //微信后台的模板信息id
            "url"=>$url, //下面为预约看房模板示例
            "data"=> array(
                "first" => array(
                    "value"=>$first,
                    "color"=>"#173177"
                ),
                "keyword1" => array(
                    "value"=>$keyword1,
                    "color"=>"#173177"
                ),
                "keyword2" => array(
                    "value"=>$keyword2,
                    "color"=>"#173177"
                ),
                "keyword3"=>array(
                    "value"=>$keyword3, //传的变量
                    "color"=>"#173177"
                ),
                "keyword4"=>array(
                    "value"=>$keyword4, //传的变量
                    "color"=>"#173177"
                ),
                "remark"=>array(
                    "value"=>$remark,//"通知时间:".date("Y-m-d H:i:s"), //传的变量
                    "color"=>"#173177"
                ),
            )
        );
        //将上面的数组数据转为json格式
        $template = json_encode($post_data);
        return $template;
    }


    /**
     * @param $url
     * @param array $data
     * @return mixed
     * curl请求
     */
    function curl_post($url , $post_data=''){

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url); //设置发送数据的网址
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //设置有返回值，0，直接显示
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0); //禁用证书验证
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);//post请求发送的数据包
        //接收执行返回的数据
        $data = curl_exec($ch);
        //关闭句柄
        curl_close($ch);
        $data = json_decode($data,true); //将json数据转成数组
        return $data;
    }
}